'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者：cacho_37967865
#博客：https://blog.csdn.net/sinat_37967865
#文件：re_model.py
#日期：2018-12-27
#备注：常用正则表达式模块
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

import re

str1 = '<div class="pl2">'
str2 = '</div>'
str3 = '<p class="pl">[美] 卡勒德·胡赛尼 / 李继宏 / ' \
       '上海人民出版社 / 2006-5 / 29.00元</p>'
str4 = '<span class="rating_nums">8.9</span>'
str5 = '<span class="pl">'
str6 = ' 1       346435人评价'
str7 = '<span class="inq">为你，千千万万遍</span>'


def match_fun():
    a1= re.match('\w',str1)
    all = re.match('.',str1)

    print("\w匹配字母和数字：",a1)
    print(r"'.'匹配所有字符串，除换行符\n以外：", all)


def search_fun():
    str1 = re.search(r'<p class="pl">(.*)</p>',str3)   # 以<p class="pl">开头，</p>结尾的非换行所有内容
    print(str1.group(1))
    str2 = re.search(r'class="pl">(.*)',str3)
    print(str2.group(1))


def findall_fun():
    str = re.findall(r'(\d.*)人评价',str6)
    print(str)

def find_char_str():
    match = re.search(r'[MGT]', 'm6240111GT3')
    print(bool(match))
    print('[amk]第一次匹配上指定的字符：',match.group())


match_fun()
search_fun()
findall_fun()
find_char_str()